sink("run.log")
cat("Starting replication at: ", as.character(Sys.time()), "\n")

library("tidyverse")
library("kableExtra")
library("estimatr")
library("ggplot2")
library("scales")
library("ggpubr")
library("ggh4x")
library("grid")
library("purrr")
library("emmeans")
library("nbpMatching")
library("blockTools")
library("DeclareDesign")
library("haven")
library("tinytable")

sessionInfo()

# R version 4.4.0 (2024-04-24)
# Platform: aarch64-apple-darwin20
# Running under: macOS Sonoma 14.4.1
# 
# Matrix products: default
# BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib 
# LAPACK: /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.0
# 
# locale:
#   [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
# 
# time zone: America/Chicago
# tzcode source: internal
# 
# attached base packages:
#   [1] stats     graphics  grDevices utils     datasets  methods   base     
# 
# other attached packages:
#   [1] tinytable_0.3.0      haven_2.5.4          DeclareDesign_1.0.10 fabricatr_1.0.2      randomizr_1.0.0      blockTools_0.6.4     nbpMatching_1.5.5    emmeans_1.10.3      
# [9] estimatr_1.0.4       kableExtra_1.4.0     lubridate_1.9.3      forcats_1.0.0        stringr_1.5.1        dplyr_1.1.4          purrr_1.0.4          readr_2.1.5         
# [17] tidyr_1.3.1          tibble_3.2.1         ggplot2_3.5.2        tidyverse_2.0.0     
# 
# loaded via a namespace (and not attached):
#   [1] tidyselect_1.2.1   viridisLite_0.4.2  farver_2.1.2       fastmap_1.2.0      TH.data_1.1-2      digest_0.6.35      rpart_4.1.23       timechange_0.3.0   estimability_1.5.1
# [10] lifecycle_1.0.4    cluster_2.1.6      survival_3.5-8     magrittr_2.0.3     compiler_4.4.0     rlang_1.1.6        Hmisc_5.1-3        tools_4.4.0        yaml_2.3.8        
# [19] data.table_1.17.0  knitr_1.46         htmlwidgets_1.6.4  plyr_1.8.9         xml2_1.3.6         RColorBrewer_1.1-3 multcomp_1.4-26    withr_3.0.2        foreign_0.8-86    
# [28] nnet_7.3-19        grid_4.4.0         xtable_1.8-4       colorspace_2.1-0   scales_1.4.0       MASS_7.3-60.2      cli_3.6.5          mvtnorm_1.2-5      rmarkdown_2.27    
# [37] generics_0.1.3     rstudioapi_0.16.0  tzdb_0.4.0         splines_4.4.0      base64enc_0.1-3    vctrs_0.6.5        Matrix_1.7-0       sandwich_3.1-0     hms_1.1.3         
# [46] Formula_1.2-5      htmlTable_2.4.2    stargazer_5.2.3    systemfonts_1.1.0  glue_1.8.0         modelsummary_2.1.1 codetools_0.2-20   stringi_1.8.7      gtable_0.3.6      
# [55] tables_0.9.28      pillar_1.10.2      htmltools_0.5.8.1  R6_2.6.1           evaluate_0.23      lattice_0.22-6     backports_1.4.1    Rcpp_1.0.12        svglite_2.1.3     
# [64] coda_0.19-4.1      gridExtra_2.3      checkmate_2.3.1    xfun_0.44          zoo_1.8-12         pkgconfig_2.0.3   



# 1_handcoding.R -- Runtime: < 1 second
start_time <- Sys.time()
source("code/1_handcoding.R", echo = TRUE, max.deparse.length = Inf)
end_time <- Sys.time()
cat("Runtime for 1_handcoding.R:",
    round(difftime(end_time, start_time, units = "secs"), 2),
    "seconds\n")

# 2_cleanreplicationdata.R -- Runtime: < 1 second
start_time <- Sys.time()
source("code/2_cleanreplicationdata.R", echo = TRUE, max.deparse.length = Inf)
end_time <- Sys.time()
cat("Runtime for 2_cleanreplicationdata.R:",
    round(difftime(end_time, start_time, units = "secs"), 2),
    "seconds\n")

# 3_tappinhewitt_blockrand.R -- Runtime: < 1 second
start_time <- Sys.time()
source("code/3_tappinhewitt_blockrand.R", echo = TRUE, max.deparse.length = Inf)
end_time <- Sys.time()
cat("Runtime for 3_tappinhewitt_blockrand.R:",
    round(difftime(end_time, start_time, units = "secs"), 2),
    "seconds\n")

# 4_descriptives.R -- Runtime: 2 seconds
start_time <- Sys.time()
source("code/4_descriptives.R", echo = TRUE, max.deparse.length = Inf)
end_time <- Sys.time()
cat("Runtime for 4_descriptives.R:",
    round(difftime(end_time, start_time, units = "secs"), 2),
    "seconds\n")

# 5_replication_simulation.R -- Runtime: 6.5 minutes
start_time <- Sys.time()
source("code/5_replication_simulation.R", echo = TRUE, max.deparse.length = Inf)
end_time <- Sys.time()
cat("Runtime for 5_replication_simulation.R:",
    round(difftime(end_time, start_time, units = "secs"), 2),
    "seconds\n")

# 6_simulation_study.R -- Runtime: 3 hours 15 minutes
start_time <- Sys.time()
source("code/6_simulation_study.R", echo = TRUE, max.deparse.length = Inf)
end_time <- Sys.time()
cat("Runtime for 6_simulation_study.R:",
    round(difftime(end_time, start_time, units = "secs"), 2),
    "seconds\n")

# 7_simulation_analysis.R -- Runtime: 2 seconds
start_time <- Sys.time()
source("code/7_simulation_analysis.R", echo = TRUE, max.deparse.length = Inf)
end_time <- Sys.time()
cat("Runtime for 7_simulation_analysis.R:",
    round(difftime(end_time, start_time, units = "secs"), 2),
    "seconds\n")

# 8_simulation_nonrandom.R -- Runtime: 5 minutes
start_time <- Sys.time()
source("code/8_simulation_nonrandom.R", echo = TRUE, max.deparse.length = Inf)
end_time <- Sys.time()
cat("Runtime for 8_simulation_nonrandom.R:",
    round(difftime(end_time, start_time, units = "secs"), 2),
    "seconds\n")

cat("Replication completed at: ", as.character(Sys.time()), "\n")
sink()
